const path = require('path');
const merge = require('webpack-merge');
// 开发环境
const dev = require('./webpack.dev');
// 生产环境
const prod = require('./webpack.prod');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');


function resolve(o) {
    return path.resolve(__dirname, o)
}

const base = {

    // 基础配置
   // entry: resolve('../src/Main.js'),
    entry: resolve('../src/index.js'),

    resolve: {
        alias: {
            '@': resolve('../static')}
    },
    output: {
        filename: 'index.js',
        //filename: 'index.js',
        path: resolve('../dist'),
       /* library:'Get3DViewer',
        libraryTarget:'commonjs2'*/
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            filename: 'index.html', // 打包出来的文件名
            template: resolve('../html/index.html'),
            hash: true,
            inject: true,
            minify: {
                removeComments: true,
                collapseWhitespace: true,
                removeAttributeQuotes: true

            },
            //favicon: resolve('../static/images/favicon.ico')
        })
    ],
    module: {
        rules: [
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader"]
            }
        ],
    }
}
module.exports = (env) =>{

    if(env.development){
        return merge.merge(base,dev);
    }else{
        return merge.merge(base,prod);
    }
}
